package state.origin;

public class ElevatorManager {
    private ElevatorState state = ElevatorState.CLOSE;

    public void open() {
        switch (state) {
            case OPEN:
                throw new UnsupportedOperationException();
            case CLOSE:
                System.out.println("打开电梯");
                this.state = ElevatorState.OPEN;
                break;
            case RUN:
                throw new UnsupportedOperationException();
            case STOP:
                System.out.println("打开电梯");
                this.state = ElevatorState.OPEN;
                break;
        }
    }

    public void close() {
        switch (state) {
            case OPEN:
                System.out.println("关闭电梯");
                this.state = ElevatorState.CLOSE;
                break;
            case CLOSE:
                throw new UnsupportedOperationException();
            case RUN:
                throw new UnsupportedOperationException();
            case STOP:
                throw new UnsupportedOperationException();
        }
    }

    public void run() {
        switch (state) {
            case OPEN:
                throw new UnsupportedOperationException();
            case CLOSE:
                System.out.println("运行电梯");
                this.state = ElevatorState.RUN;
                break;
            case RUN:
                throw new UnsupportedOperationException();
            case STOP:
                System.out.println("运行电梯");
                this.state = ElevatorState.RUN;
                break;
        }
    }

    public void stop() {
        switch (state) {
            case OPEN:
                throw new UnsupportedOperationException();
            case CLOSE:
                throw new UnsupportedOperationException();
            case RUN:
                System.out.println("停止电梯");
                this.state = ElevatorState.STOP;
                break;
            case STOP:
                throw new UnsupportedOperationException();
        }
    }

}
